package com.lsh.controller;

import com.lsh.service.SysService;
import com.lsh.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ：LiuShihao
 * @date ：Created in 2020/11/9 1:54 下午
 * @desc ：
 */
@Slf4j
@Controller
public class LoginController {
    @Autowired
    SysService sysService;

    @Autowired
    UserService userService;


    @GetMapping("/")
    public String showHome() {
        /**
         * 从session中获取登录信息,判断有无登录
         */
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        log.info("/方法执行");
        log.info("登陆账号:"+name);
        return "home";
    }

    /**
     * 跳转至登录页面
     * @return
     */
    @GetMapping("/login")
    public String showLogin() {
        log.info("/login方法执行");
        return "index";
    }

    /**
     * User服务调用Dept服务  负载均衡 Fegin
     * @return
     */
    @GetMapping("/dept")
    @ResponseBody
    public String callDept() {
        log.info("调用dept服务");
        String dept = userService.dept();
        return dept;
    }
}
